//#define BAKED_MESH_DRAW
#ifdef BAKED_MESH_DRAW
#define NO_MESH_DRAW
#include "MeshDrawBaked.hpp"
typedef MeshDrawBaked MeshDraw;
#else
//#if 1
//#include "MeshDraw2Side.hpp"
//typedef MeshDraw2Side MeshDraw;
//#else

#ifndef MESHDRAW_HPP
#define MESHDRAW_HPP


#include "Color.hpp"
#include "Mat4.hpp"
#include "Mesh.hpp"

class MeshDraw
{
   public:

      static const float sMaterialColors[18][3];

      MeshDraw();

      void EnableMaterials(bool aUseMaterials) { mUseMaterials = aUseMaterials; }

      void DrawSection(int aSection, float aAlpha = 1.0);

      int  GetSectionCount() { return mSections.size(); }
      
      int  GetSectionMaterial(int aSection) { return mSections[aSection].mMaterialIndex; }
      void Draw(float aAlpha = 1.0);
      
      void SetMesh(const Mesh& aMesh);

      const Mesh& GetMesh() { return *mMeshPtr; }

      void BindVertexBuffer();

      void BindIndexBuffer();

      void ReleaseVertexBuffer();

      void ReleaseIndexBuffer();

      static Color GetMaterialColor(int aMaterial);

   private:

      void DrawSectionP(int aSection, float aAlpha = 1.0f);

      void LoadVBO();

      void UnbindVBO();

      void PrepareBuffers();

      Mesh* mMeshPtr;
#pragma pack(push, 1)
      struct Vertex
      {
         Vec3  p;
         Vec3  n;
      };
#pragma pack(pop)
      struct MaterialSection
      {
         int   mOffset;
         int   mFaceCount;
         int   mMaterialIndex;
         Color mColor;
      };
      typedef std::vector<Vertex> VertexList;
      bool mUseMaterials;
      VertexList                 mVertices;
      std::vector<int>  mIndices;
      std::vector<MaterialSection>  mSections;

      unsigned int mVBO_Buffers[2];

      std::vector<Vec3> mCentroids;
};
#endif

#endif